home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 7: Sunsite / Linux Cubed Series 7 - Sunsite Vol 1.iso / system / shells / scsh-0.4 / scsh-0 / scsh-0.4.2 / scsh / bdbmo.c < prev    next >
C/C++ Source or Header  |  1995-10-13  |  3KB  |  108 lines

  1. /* Scheme48/scsh Unix system interface.
  2. ** Routines that require custom C support.
  3. ** Copyright (c) 1995 by David Albertz.
  4. */
  5.  
  6. #include <stdio.h>
  7. #include <errno.h>
  8. #include <db.h>
  9. #include <sys/types.h>
  10. #include <limits.h>
  11.  
  12. #include "cstuff.h"
  13.  
  14. extern int errno;
  15.  
  16. /* stub used to return TRUE when scheme checks for Berkeley dbm */
  17. int db_check()
  18. {
  19.   return 1;
  20.   }
  21.  
  22. scheme_value db_open_default(char *file, int flags, int mode, DB **db_ptr)
  23. {
  24.     *db_ptr = dbopen(file, flags, mode, DB_BTREE, NULL);
  25.     if(*db_ptr == NULL)
  26.     return -1;
  27.     else
  28.     return 0;
  29.     }
  30.  
  31. /*  Open a btree type database
  32.     Note: if pass_info is set to zero, all subsequent arguments are
  33.           ignored, otherwise they are loaded into a BTREEINFO structure
  34.           and passed to the open routine */
  35. scheme_value db_open_btree (char *file, int flags, int mode, int pass_info,
  36.              int access_flags, int cachesize, int maxkeypage,
  37.              int minkeypage, int psize, int lorder, DB **db_ptr)
  38. {
  39.     BTREEINFO btree;
  40.     if (pass_info)
  41.     {
  42.     btree.flags = access_flags;
  43.     btree.cachesize = cachesize;
  44.     btree.maxkeypage = maxkeypage;
  45.     btree.minkeypage = minkeypage;
  46.     btree.psize = psize;
  47.     btree.compare = NULL;
  48.     btree.prefix = NULL;
  49.     btree.lorder = lorder;
  50.     *db_ptr = dbopen(file, flags, mode, DB_BTREE, &btree);
  51.     }
  52.     else
  53.     *db_ptr = dbopen(file, flags, mode, DB_BTREE, NULL);
  54.     if(*db_ptr == NULL)
  55.     return -1;
  56.     else
  57.     return 0;
  58.     }
  59.  
  60. /*  Open a hash type database (same use of pass_info as in btree) */
  61. scheme_value db_open_hash (char *file, int flags, int mode, int pass_info,
  62.              int bsize, int ffactor, int nelem, int cachesize,
  63.              int lorder, DB **db_ptr)
  64. {
  65.     HASHINFO hash;
  66.     if (pass_info)
  67.     {
  68.     hash.bsize = bsize;
  69.     hash.ffactor = ffactor;
  70.     hash.nelem = nelem;
  71.     hash.cachesize = cachesize;
  72.     hash.hash = NULL;
  73.     hash.lorder = lorder;
  74.     *db_ptr = dbopen(file, flags, mode, DB_HASH, &hash);
  75.     }
  76.     else
  77.     *db_ptr = dbopen(file, flags, mode, DB_HASH, NULL);
  78.     if(*db_ptr == NULL)
  79.     return -1;
  80.     else
  81.     return 0;
  82.     }
  83.  
  84. /*  Open a recno type database (with same use of pass_info again) */
  85. scheme_value db_open_recno (char *file, int flags, int mode, int pass_info,
  86.              int access_flags, int cachesize, int psize, int lorder,
  87.              int reclen, char bval, char *bfname, DB **db_ptr)
  88. {
  89.     RECNOINFO recno;
  90.     if (pass_info)
  91.     {
  92.     recno.flags = access_flags;
  93.     recno.cachesize = cachesize;
  94.     recno.psize = psize;
  95.     recno.lorder = lorder;
  96.     recno.reclen = reclen;
  97.     recno.bval = bval;
  98.     recno.bfname = bfname;
  99.     *db_ptr = dbopen(file, flags, mode, DB_RECNO, &recno);
  100.     }
  101.     else
  102.     *db_ptr = dbopen(file, flags, mode, DB_RECNO, NULL);
  103.     if(*db_ptr == NULL)
  104.     return -1;
  105.     else
  106.     return 0;
  107.     }
  108.